import Vue from "vue";
import Vuex from "vuex";
import config from "@/config/config.js";

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    version: config.environment.version,
    app_id: "market", // 测试环境和线上环境
    domain: config.environment.domain,
    userinfo: {},
    API: config.environment.api,
    subject: "",
    loading: false,
    imgUrl: "",
  },
  getters: {
    // 通过方法访问
    api: (state) => state.API,		
    imgUrl: () => (process.env.NODE_ENV === "development" ? `/${config.environment.apiImg}` : `${window.location.origin}${config.environment.apiImg}`),
    getSubject: (state) => state.subject
    ,
  },
  mutations: {
    changeMarketPageName(state, data) {
      state.marketPageName = data;
    },
    setLoading: (state) => {
      state.loading = true;
    },
    cancalLoading: (state) => {
      state.loading = false;
    },
  },
});

export default store;
